Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
throttleit
Advanced tools
The throttleit package is a utility that allows you to throttle a function, meaning it limits the rate at which a function can fire. This is particularly useful for handling repetitive events that you want to control, such as window resizing, scrolling, or keypresses in a performant way.
Throttling function calls
This code sample demonstrates how to use throttleit to throttle a window resize event handler. The onResize function will not be called more than once every 200 milliseconds, no matter how often the resize event fires.
const throttle = require('throttleit');
function onResize(event) {
console.log('Window resized.');
}
window.addEventListener('resize', throttle(onResize, 200));
lodash.throttle is a function from the popular Lodash library that provides a similar throttling functionality. It is often used for the same purposes as throttleit but comes as part of a larger utility library, which might be more suitable for projects that already use Lodash for other utilities.
Bottleneck is a package that is more focused on rate-limiting and not just throttling. It can be used to limit the execution of functions to a maximum number of times per interval, which is useful for managing API rate limits or other scenarios where you need a more robust solution than simple throttling.
Throttle a function
$ component install component/throttle
$ npm install throttleit
// with component:
var throttle = require('throttle');
// with npm:
// var throttle = require('throttleit');
window.onresize = throttle(resize, 200);
function resize(e) {
console.log('height', window.innerHeight);
console.log('width', window.innerWidth);
}
Creates a function that will call fn
at most once every wait
milliseconds.
Supports leading and trailing invocation.
fn
will receive last context (this
) and last arguments passed to a throttled wrapper before fn
was invoked.
MIT
FAQs
Throttle a function to limit its execution rate
The npm package throttleit receives a total of 2,432,694 weekly downloads. As such, throttleit popularity was classified as popular.
We found that throttleit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.